﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OOLib
{
   /// <summary>
   /// Manages and creates frames.
   /// </summary>
   /// <remarks>
   /// Frames may contain other frames (by implementing an XFrames interface) and may be contained in other frames.
   /// </remarks>
   public class Frames : IndexAccess, IFrames
   {
      #region Constructors

      /// <summary>
      /// Constructor
      /// </summary>
      /// <remarks>
      /// After using this constructor, the ComObj must be set manually!
      /// </remarks>
      public Frames() :
         base()
      { }

      /// <summary>
      /// Constructor
      /// </summary>
      /// <param name="comObject">COM object</param>
      public Frames(object comObject) :
         base(comObject)
      { }

      #endregion

      #region IFrames

      /// <summary>
      /// Appends the specified Frame to the list of sub-frames. 
      /// </summary>
      /// <param name="frame">New frame for inserting into this container</param>
      /// <remarks>!!! Not tested !!!</remarks>
      public void AppendFrame(Frame frame)
      {
         CheckDisposed();
         InvokeMethod("appendFrame", frame.ComObj);
      }

      /// <summary>
      /// Provides access to the list of all currently existing frames inside this container and her sub frames.
      /// </summary>
      /// <param name="searchFlags">Use combinations of FrameSearchFlag to specify which frames should be found.</param>
      /// <returns>Returns all frames of this container and all available frames of the whole frame tree which match search parameter SearchFlags.</returns>
      /// /// <remarks>!!! Not tested !!!</remarks>
      public Frame[] QueryFrames(FrameSearchFlag searchFlags)
      {
         CheckDisposed();
         object[] rawFrames = (object[])InvokeMethod("queryFrames", (int)searchFlags);
         var frames = new Frame[rawFrames.Length];
         for (int i = 0; i < rawFrames.Length; i++)
         {
            frames[i] = GetObjectWrapper<Frame>(rawFrames[i]);
         }
         return frames;
      }

      /// <summary>
      /// Removes the frame from its container.
      /// </summary>
      /// <param name="frame">Frame which should be removed from this container.</param>
      /// <remarks>
      /// Note: 
      /// The method XComponent::dispose() is not called implicitly by this method. 
      /// The creator attribute of the frame must be reset by the caller of this method. 
      /// !!! Not tested !!!
      /// </remarks>
      public void Remove(Frame frame)
      {
         CheckDisposed();
         InvokeMethod("removeFrame", frame.ComObj);
      }

      #endregion
   }

   /// <summary>
   /// Manages and creates frames.
   /// </summary>
   /// <remarks>
   /// Frames may contain other frames (by implementing an XFrames interface) and may be contained in other frames.
   /// </remarks>
   public interface IFrames
   {
      /// <summary>
      /// Appends the specified Frame to the list of sub-frames. 
      /// </summary>
      /// <param name="frame">New frame for inserting into this container </param>
      void AppendFrame(Frame frame);

      /// <summary>
      /// Provides access to the list of all currently existing frames inside this container and her sub frames.
      /// </summary>
      /// <param name="searchFlags">Use combinations of FrameSearchFlag to specify which frames should be found.</param>
      /// <returns>Returns all frames of this container and all available frames of the whole frame tree which match search parameter SearchFlags.</returns>
      Frame[] QueryFrames(FrameSearchFlag searchFlags);

      /// <summary>
      /// Removes the frame from its container.
      /// </summary>
      /// <param name="frame">Frame which should be removed from this container.</param>
      /// <remarks>
      /// Note: 
      /// The method XComponent::dispose() is not called implicitly by this method. 
      /// The creator attribute of the frame must be reset by the caller of this method. 
      /// </remarks>
      void Remove(Frame frame);
   }
}
